<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:c="livcos.org/ns/cosmos"
  xmlns:job="livcos.org/ns/process/job"
  exclude-result-prefixes="c">
  
  <xsl:import href="list.xsl"/>

	<xsl:template match="/">
    <xsl:apply-templates select="$snapshot"/>
    <job:feed stream="response" base="job" content-type="text/html; charset=UTF-8">
      <p>
        The snapshot has been generated to '<xsl:value-of select="$snapshot/target/@url"/>'.
      </p>
    </job:feed>
  </xsl:template>
  
	<xsl:template match="snapshot">
		<xsl:apply-templates select="resource"/>
	</xsl:template>
	
	<xsl:template match="replace">
	</xsl:template>
	
	<xsl:template match="resource">
    <xsl:variable name="ref">
      <xsl:if test="not(starts-with(@ref,'/'))">
        <xsl:value-of select="../source/@root"/>
        <xsl:text>/</xsl:text>
      </xsl:if>
      <xsl:value-of select="@ref"/>
    </xsl:variable>
    <job:feed ref="{$ref}" stream="{../target/@url}/{@out}"/>
  </xsl:template>
  
  <xsl:template match="resource[ends-with(@out,'.html')]">
    <xsl:variable name="ref">
      <xsl:if test="not(starts-with(@ref,'/'))">
        <xsl:value-of select="../source/@root"/>
        <xsl:text>/</xsl:text>
      </xsl:if>
      <xsl:value-of select="@ref"/>
    </xsl:variable>
    <job:feed ref="/livcos.org/web/admin/snapshot/view.view" stream="{../target/@url}/{@out}">
      <job:param name="ref" value="{$ref}"/>
      <job:param name="list" value="{$list}"/>
    </job:feed>
  </xsl:template>
  
</xsl:stylesheet>
